package com.tox.action;

import java.io.ByteArrayInputStream;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.tox.util.SecurityCode;
import com.tox.util.SecurityImage;

public class SecurityCodeImageAction extends ActionSupport implements SessionAware {
	private Map<String, Object> session;
	private ByteArrayInputStream imageStream;
	
	@Override
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}

	public ByteArrayInputStream getImageStream() {
		return imageStream;
	}

	public void setImageStream(ByteArrayInputStream imageStream) {
		this.imageStream = imageStream;
	}
	
	public String execute()  throws Exception{
		String securityCode=SecurityCode.getSecurityCode();
		imageStream=SecurityImage.getImageAsInputStream(securityCode);
		session.put("SESSION_SECURITY_CODE", securityCode);
		
		System.out.println(securityCode);
		System.out.println(session.get("SESSION_SECURITY_CODE").toString());
		return SUCCESS;
		
	}

}
